package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaishengit.entity.Comp;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class CompDao {

	private DBHelp<Comp> db = new DBHelp<Comp>();

	public Comp findByComName(String compName) {
		String sql = "select id ,compname from t_comp where compname=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), compName);
	}

	public Comp findByComId(String compId) {
		String sql = "select id ,compname from t_comp where id=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), compId);
	}

	public void save(String compid, String compName) {
		String sql = "insert into t_comp(id,compname) values(?,?)";
		db.executeSQL(sql, compid, compName);
	}

	private class CompRowMapper implements RowMapper<Comp> {

		public Comp mapperRow(ResultSet rs) throws SQLException {

			Comp comp = new Comp();
			comp.setId(rs.getString("id"));
			comp.setCompname(rs.getString("compname"));

			return comp;
		}
	}
}
